<template>
  <div class="hm-login">
    <div class="title">面经注册</div>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button
          square
          block
          type="info"
          native-type="submit"
          color="#07c160"
          >提交</van-button
        >
      </div>
    </van-form>
    <router-link to="/login" class="link">有账号,去登录</router-link>
  </div>
</template>
<script>
import { register } from "@/api/user";
export default {
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    async onSubmit() {
      if (this.username === "" || this.password === "") {
        return;
      }
      await register({ username: this.username, password: this.password });
      this.$router.push("/login");
      this.$toast("注册成功");
    },
  },
};
</script>

<style lang="less" scoped>
.title {
  text-align: center;
  height: 50px;
  line-height: 50px;
}
.link {
  padding-right: 5.33333vw;
  float: right;
  color: #006699;
  font-size: 12px;
}
</style>
